package com.leecode.week.w233;

public class P01 {
    public static void main(String[] args) {
        P01 p = new P01();
        int i = p.maxAscendingSum(new int[]{1, 2, 3, 1,2});
        System.out.println(i);
    }

    public int maxAscendingSum(int[] nums) {
        int max = nums[0];
        int start = 0;
        int end = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] <= nums[i - 1]) {
                int p = nums[start];
                for (int j = start + 1; j <= end; j++) {
                    p += nums[j];
                }
                if (p > max) {
                    max = p;
                }
                start = i;
                end = i;
            } else {
                end++;
            }
        }
        int p = nums[start];
        for (int j = start + 1; j <= end; j++) {
            p += nums[j];
        }
        if (p > max) {
            max = p;
        }
        return max;
    }
}
